<template>
	<view :style="colorStyle">
		<view class="my-order">
			<!-- <view class="header bg-color">
				<view class="picTxt acea-row row-between-wrapper">
					<view class="text">
						<view class="name">订单信息</view>
						<view>消费订单：{{ orderData.order_count || 0 }} 总消费：￥{{ orderData.sum_price || 0 }}</view>
					</view>
					<view class="pictrue">
						<image src="../static/orderTime.png"></image>
					</view>
				</view>
			</view> -->
			
			<view class="head-bar">
				<u-tabs
					:list="tabList"
					@click="tabClick"
					:current="tabCurrent"
					:lineColor="appType == 1 ? '#FF6933' : appType == 2 ? '#297EFF' : '#39CCC2'" 
					:inactiveStyle="{ color: '#999999' }"
					:activeStyle="{ color: '#1F1F1F', fontWeight: 'bold' }"
					lineWidth="48rpx"
					lineHeight="4rpx"
				></u-tabs>
			</view>
			
			<view style="height: 98rpx;"> </view>
			
			<Loading :loaded="loaded" :loading="loading"></Loading>
			<view class="list">
				<view class="item" v-for="(item, index) in orderList" :key="index">
					<view @click="goOrderDetails(item.order_id)">
						<view class="title acea-row row-between-wrapper">
							
							<view class="acea-row row-middle">
								
								<image class="icon-mer" src="../../../static/images/icon-mer.png"></image>
								
								<text>直租侠</text>
							</view>
							
							<!-- <view class="acea-row row-middle">
								<text class="sign cart-color acea-row row-center-wrapper"
									v-if="item.type == 2">砍价</text>
								<text class="sign cart-color acea-row row-center-wrapper"
									v-else-if="item.type == 3">拼团</text>
								<text class="sign cart-color acea-row row-center-wrapper"
									v-else-if="item.type == 1">秒杀</text>
								<view>{{ item._add_time }}</view>
							</view> -->
							
							
							<!-- -------------------------------------------------------------- -->
							
							<view v-if="item._status._type == 11" class="f-color app-font-color">待审核</view>
							<view v-else-if="item._status._type == 0" class="f-color app-font-color">待付款</view>
							<view v-else-if="item._status._type == 1" class="">待发货</view>
							<view v-else-if="item._status._type == 111" class="">首期待支付</view>
							<view v-else-if="item._status._type == 2" class="">待收货</view>
							<!-- <view v-else-if="item._status._type == 3" class="">待归还</view> -->
							<view v-else-if="item._status._type == 33" class="">租用中</view>
							<view v-else-if="item._status._type == 4" class="">已完成</view>
							
							<!-- <view v-if="item._status._type == 9" class="font-color">线下付款,未支付</view>
							<view v-else-if="item._status._type == 0" class="font-color">待付款</view>
							<view v-else-if="item._status._type == 1 && (item.shipping_type == 1 || item.shipping_type == 3)" class="font-color">待发货
							   <text v-if="item.refund.length">{{item.is_all_refund?'，退款中':'，部分退款中'}}</text>
							</view>
							<view v-else-if="item._status._type == 1 && (item.shipping_type == 2 || item.shipping_type == 4)"  class="font-color">
								{{item.shipping_type == 2?'待核销':'待收货'}}
								 <text v-if="item.refund.length">{{item.is_all_refund?'，退款中':'，部分退款中'}}</text>
							</view>
							<view v-else-if="item._status._type == 2" class="font-color">待收货
							   <text v-if="item.refund.length">{{item.is_all_refund?'，退款中':'，部分退款中'}}</text>
							</view>
							<view v-else-if="item._status._type == 3" class="font-color">待评价
							   <text v-if="item.refund.length">{{item.is_all_refund?'，退款中':'，部分退款中'}}</text>
							</view>
							<view v-else-if="item._status._type == 4" class="font-color">已完成
							   <text v-if="item.refund.length">{{item.is_all_refund?'，退款中':'，部分退款中'}}</text>
							</view>
							<view v-else-if="item._status._type == -2" class="font-color">已退款
							</view>
							<view v-else-if="item._status._type == 5 && item.status == 0" class="font-color">待核销
							  <text v-if="item.refund.length">{{item.is_all_refund?'，退款中':'，部分退款中'}}</text>
							</view>
							<view v-else-if="item._status._type == 5 && item.status == 5" class="font-color">部分核销
							  <text v-if="item.refund.length">{{item.is_all_refund?'，退款中':'，部分退款中'}}</text>
							</view>
							<view v-else-if="item._status._type == -1" class="font-color">申请退款
							</view> -->
						</view>
						<view class="item-info acea-row row-between row-top" v-for="(items, index) in item.cartInfo"
							:key="index">
							<view class="pictrue">
								<image :src="items.productInfo.image"></image>
							</view>
							<view class="text acea-row">
								<view class="name line2">{{ items.productInfo.store_name }}</view>
								
								<view class="sku-item">已选择：{{item.bill.lease_way}}{{items.productInfo.attrInfo.suk}}{{item.lease_term.label}}；1件</view>
								<view class="sku-item2">预估租期：{{item.lease_term.start_date}}-{{ item.lease_term.end_date }}</view>
								<!-- <view class="money"> -->
									<!-- <view v-if="items.productInfo.attrInfo">￥{{ items.productInfo.attrInfo.price }}</view> -->
									<!-- <view v-else>￥{{ items.productInfo.price }}</view>
									<view>x{{ items.cart_num }}</view>
									<view v-if="items.refund_num && item._status._type != -2" class="return">{{ items.refund_num }}件退款中</view> -->
								<!-- </view> -->
							</view>
						</view>
						<!-- <view class="totalPrice">
							共{{ item.total_num || 0 }}件商品，总金额
							<text class="money">￥{{ item.pay_price }}</text>
						</view> -->
					</view>
					<view class="rent">共{{item.lease_term.label}}，总租金<text class="money">¥<text class="num">{{item.rent_price}}</text></text></view>
					<!-- <view class="rent">意外险<text class="money">¥<text class="num">{{item.broker_screen_insurance}}</text></text></view> -->
					<view class="bottom acea-row row-between">
						<view class="acea-row row-middle">
							<!-- <view v-if="item._status._type == 0" class="cancle-msg">{{item._status._msg}}</view> -->
						</view>
						<view class="acea-row row-right row-middle">
							<view class="bnt cancelBnt" @click="toQuestion(item.id)">客户问卷</view>
							<view class="bnt cancelBnt" @click="callPhone(item.merchantAddress[0].phone)">联系商家</view>
							<view class="bnt cancelBnt" v-if="item._status._type == 2" @click="openTimeLine(item.order_id)">查看物流</view>
							<view class="bnt cancelBnt" v-if="item._status._type == 4 || item._status._type == 111 || item._status._type == 1 || item._status._type == 3 || orderInfo._status._type == 2 " @click="goBillList(item.order_id, item.id)">查看账单</view>
							<view class="bnt cancelBnt" v-if="item.type == -4" @click="cancelOrder(index, item.order_id)">取消订单</view>
						<!-- 	<view class="bnt b-color" v-if="item._status._type == 3 && item.isPayOff"
								@click="">立即寄回</view> -->
							
							<view class="bnt b-color app-b-color" v-if="item.user.is_attestation == 1 && item._status._type == 0 && item.is_contract == 3"
								@click="goPay(item.order_id, item.id, item.is_contract)">立即支付</view>
								
							<view class="bnt b-color app-b-color" v-if="item.user.is_attestation == 1 && item._status._type == 0 && item.is_contract !== 3"
								@click="goPay(item.order_id, item.id, item.is_contract)">立即签约</view>
						
							<view class="bnt b-color app-b-color" v-if="item.user.is_attestation == 0" @click="goPay(item.order_id, item.id)">去实名</view>
					
							<view class="bnt b-color app-b-color" v-if="item._status._type == 111"
								@click="goPay2(item.id, item.waitBillOrderId)">首期支付</view>
								
							<view class="bnt b-color app-b-color" v-if="item._status._type == 2"
								@click="confirmOrder(item.order_id)">确认签收</view>
								
								
				<!-- 			<view class="bnt cancelBnt" v-if="item._status._type == 4"
								@click="delOrder(item.order_id, index)">删除订单</view> -->
							<!-- <view class="bnt b-color" @click="goOrderDetails(item.order_id)">查看详情</view> -->
						</view>
					</view>
				</view>
			</view>
			<view class="loadingicon acea-row row-center-wrapper" v-if="orderList.length > 0">
				<text class="loading iconfont icon-jiazai" v-if="loading == true"></text>
				{{ loadTitle }}
			</view>
			<view v-if="orderList.length == 0 && !loading">
				<emptyPage title="暂无订单信息~"></emptyPage>
			</view>
		</view>
		<!-- <home v-if="navigation"></home> -->
		<!-- <payment :payMode="payMode" :pay_close="pay_close" @onChangeFun="onChangeFun" :order_id="pay_order_id"
			:totalPrice="totalPrice"></payment> -->
			
		<payWindow :payMode="payMode" :pay_close="pay_close" @onChangeFun="onChangeFun" :order_id="pay_order_id"
			:totalPrice="totalPrice"></payWindow>
			
		<!-- #ifdef MP -->
		<authorize v-if="isShowAuth" @authColse="authColse" @onLoadFun="onLoadFun"></authorize>
		<!-- #endif -->
		
		
		<u-popup mode="bottom" :show="showTimeline" @close="closePopup" round="24" :closeOnClickOverlay="true">
			<view class="timeline">
				<text class='iconfont icon-guanbi popup-close' @click='showTimeline = false'></text>
				<view class="timeline-name">物流信息</view>
				<view class="timeline-nav">
					<view style="display: flex;align-items: center;">
						<!-- <image src="https://kuaidi2021.oss-cn-hangzhou.aliyuncs.com/attach/2023/02/a45bf202302040210411960.png"></image> -->
						<text style="margin-left: 24rpx;">快递单号：{{delivery_id}}</text>
						
					</view>
					<view class="val" @click="copy(delivery_id)">
						<image src="../../../static/images/icon/copy-2.png"></image>
					</view>
				
					
				</view>
				<scroll-view class="list" scroll-y="true">
					<view class="item" v-for="item in expressList">
						<view class="circle"></view>
						<view class="title">
							{{ item.status }}
							<view class="time">{{ item.time }}</view>
						</view>
					</view>
					<view class="line"></view>
				</scroll-view>
				
				<!-- <button class="pop-btn" @click="showTimeline = false">{{$t(`确认`)}}</button> -->
			</view>
		</u-popup>
		
		<callMerPhone ref="callPhone"></callMerPhone>
	</view>
</template>

<script>
	let app = getApp();
	import callMerPhone from '@/components/callMerPhone.vue'
	import {
		getOrderList,
		orderData,
		orderCancel,
		orderDel,
		orderPay,
		orderTake,
		express,
		isContract,
		contract,
		getStageBillPay2,
		userSign
	} from '@/api/order.js';
	import {
		getUserInfo,
		isAttestation,
	} from '@/api/user.js';
	import {
		openOrderSubscribe
	} from '@/utils/SubscribeMessage.js';
	import home from '@/components/home';
	import payment from '@/components/payment';
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from 'vuex';
	import emptyPage from '@/components/emptyPage.vue';
	import colors from '@/mixins/color.js';
	import Loading from '@/components/Loading/index.vue'
	import payWindow from '@/components/payWindow';
	export default {
		components: {
			Loading,
			payment,
			home,
			emptyPage,
			callMerPhone,
			payWindow
		},
		mixins:[colors],
		data() {
			return {
				appType: app.globalData.appType,
				delivery_id: '',
				expressList: [],
				showTimeline: false,
				timeLineObj: {},
				tabCurrent: 0,
				tabList: [
					{name: '全部',id: ""},
					{name: '待审核',id: '11'},
					{name: '待付款',id: '0'},
					{name: '首期待支付',id: '15'},
					{name: '待发货',id: '12'},
					{name: '待收货',id: '2'},
					{name: '租用中',id: '16'},
					// {name: '待归还',id: '3'},
					{name: '已完成',id: '4'},
				],
				loaded: false,
				loading: false, //是否加载中
				loadend: false, //是否加载完毕
				loadTitle: '加载更多', //提示语
				orderList: [], //订单数组
				orderData: {}, //订单详细统计
				orderStatus: '', //订单状态
				page: 1,
				limit: 20,
				payMode: [
					// {
					// 	name: '微信支付',
					// 	icon: 'icon-weixinzhifu',
					// 	value: 'weixin',
					// 	title: '使用微信快捷支付',
					// 	payStatus: true
					// },
					{
						name: '支付宝支付',
						icon: 'icon-zhifubao',
						value: 'alipay',
						title: '使用线上支付宝支付',
						payStatus: true
					},
					{
						name: '银行卡支付',
						icon: 'icon-yuezhifu',
						value: 'yee_yjzf',
						title: '当前可用余额：',
						number: 0,
						payStatus: true
					}
				],
				pay_close: false,
				pay_order_id: '',
				totalPrice: '0',
				isAuto: false, //没有授权的不会自动授权
				isShowAuth: false //是否隐藏授权
			};
		},
		computed: mapGetters(['isLogin']),
		onShow() {
			console.log('onShow')
			uni.removeStorageSync('form_type_cart');
			this.page = 1;
			this.loadend = false;
			this.orderList = [];
			// if (this.isLogin) {
				this.getFun();
			// } else {
			// 	// #ifdef H5 || APP-PLUS
			// 	toLogin()
			// 	// #endif
			// 	// #ifdef MP
			// 	this.isShowAuth = true;
			// 	// #endif
			// }
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad(options) {
			if (options.status) this.orderStatus = (options.status==undefined && options.status!=0)?'':parseInt(options.status);
			switch (this.orderStatus) {
				case '':
					this.tabCurrent = 0
					break
				case 11:
					this.tabCurrent = 1
					break
				case 0:
					this.tabCurrent = 2
					break
				case 12:
					this.tabCurrent = 4
					break
				case 4:
					this.tabCurrent = 5
					break
			}
			
			if (this.isLogin) {
				my.getAuthCode({
				  // 订单服务授权：order_service。如需同时获取用户多项授权，可在 scopes 中传入多个 scope 值。
				  scopes: ['order_service'],
				  success: (res) => {
					// 订单服务授权成功
				  },
				  fail: (res) => {
					// 订单服务授权失败，根据自己的业务场景来进行错误处理
				  },
				});
			}
		},
		methods: {
			toQuestion(id) {
				uni.navigateTo({
					url: '/pages/lease/question?orderId=' + id
				})
			},
			copy: function(val) {
				let that = this;
				uni.setClipboardData({
					data: val,
					success: () =>
						uni.showToast({
						title: '已复制'
					})
				});
			},
			goPay2(id, arr) {
				const  that = this
				uni.showLoading({
					title: '支付中'
				})
				getStageBillPay2(id, {
					order_id: arr
				}).then(res => {
					uni.hideLoading()
					const prePayTn = res.data.result.jsConfig.prePayTn
					my.tradePay({
						tradeNO: prePayTn ? prePayTn : res.data.result.jsConfig.tradeNo,
						success: (resd) => {
							if (
							  resd.resultCode == "9000" ||
							  resd.resultCode == "8000" ||
							  resd.resultCode == "6004"
							) {
							  uni.showToast({
							  	title: '支付成功'
							  })
							  that.loadend = false;
							  that.page = 1;
							  that.$set(that, 'orderList', []);
							  that.getOrderList();
							} else {
								return that.$util.Tips({
									title: '支付失败'
								});
								
							}
						},
						fail: (resd) => {
							console.log(resd, "支付状态");
						}
					})
				})
			},
			callPhone(phone){
				this.$refs.callPhone.openCall(phone)
			},
			openTimeLine(order_id){
				uni.showLoading({
					title: '加载中'
				})
				
				let that = this;
				express(order_id).then(function(res) {
					that.showTimeline = true
					uni.hideLoading()
					let result = res.data.express.result || {};
					that.$set(that, 'expressList', result.list || []);
					that.delivery_id = res.data.order.delivery_id
				}).catch((error) => {
					uni.hideLoading()
					this.$util.Tips({
						title: error
					});
				});
				
				
			},
			closePopup(){
				this.showTimeline = false
			},
			confirmOrder(orderId) {
				let that = this;
				uni.showModal({
					title: '是否主动确认收货',
					content: '确认收货后需要立即支付账单费用，您可等待系统自动确认收货',
					success: function(res) {
						if (res.confirm) {
							orderTake(orderId).then(res => {
								that.$util.Tips({
									title: '操作成功',
									icon: 'success'
								})
								that.page = 1;
								that.loadend = false;
								that.$set(that, 'orderList', []);
								that.getOrderList();
							}).catch(err => {
								return that.$util.Tips({
									title: err
								});
							})
						}
					}
				})
			},
			getFun(){
				this.getOrderData();
				this.getOrderList();
				this.getUserInfo();
			},
			onLoadFun(){
				this.getFun();
				this.isShowAuth = false;
			},
			// 授权关闭
			authColse: function(e) {
				this.isShowAuth = e;
			},
			/**
			 * 事件回调
			 *
			 */
			onChangeFun: function(e) {
				let opt = e;
				let action = opt.action || null;
				let value = opt.value != undefined ? opt.value : null;
				action && this[action] && this[action](value);
			},
			
			/**
			 * 关闭支付组件
			 *
			 */
			payClose: function() {
				this.pay_close = false;
			},
			
			
			payCheck(value) {
				const that = this
				this.pay_close = false;
				uni.showLoading({
					title: '加载中'
				})
				
				orderPay({
					uni: this.pay_order_id,
					paytype: value,
					'from': 'weixin',
					quitUr: ''
				}).then(res => {
					uni.hideLoading()
					
					if (value === 'alipay') {
						const prePayTn = res.data.result.jsConfig.prePayTn
						my.tradePay({
							tradeNO: prePayTn ? prePayTn : res.data.result.jsConfig.tradeNo,
							success: (resd) => {
								if (
								  resd.resultCode == "9000" ||
								  resd.resultCode == "8000" ||
								  resd.resultCode == "6004"
								) {
								  
								  that.loadend = false;
								  that.page = 1;
								  that.$set(that, 'orderList', []);
								  that.getOrderList();
								  console.log(resd, "支付完成");
								} else {
								  console.log(resd, "支付失败");
								}
							},
							fail: (resd) => {
								console.log(resd, "支付状态");
							}
						})
					} else {
						const url = res.data.result.jsConfig.cashierUrl
						uni.navigateTo({
							url: `/pages/annex/web_view/index?url=${url}`
						});
					}
				})
				
			},
			
			/**
			 * 获取用户信息
			 *
			 */
			getUserInfo: function() {
				let that = this;
				// getUserInfo().then(res => {
					// that.payMode[2].number = res.data.now_money;
					// that.$set(that, 'payMode', that.payMode);
				// });
			},
			/**
			 * 关闭支付组件
			 *
			 */
			payClose: function() {
				this.pay_close = false;
			},
			/**
			 * 获取订单统计数据
			 *
			 */
			getOrderData: function() {
				let that = this;
				orderData().then(res => {
					that.$set(that, 'orderData', res.data);
					// that.payMode.map(item => {
					// 	if (item.value == 'weixin') {
					// 		item.payStatus = res.data.pay_weixin_open ? true : false;
					// 	}
					// 	if (item.value == 'alipay') {
					// 		item.payStatus = res.data.ali_pay_status ? true : false;
					// 	}
					// 	if (item.value == 'yue') {
					// 		item.payStatus = res.data.yue_pay_status == 1 ? true : false;
					// 	}
					// });
					// //#ifdef MP
					// this.payMode[1].payStatus = false;
					// //#endif
				});
			},
			/**
			 * 取消订单
			 *
			 */
			cancelOrder: function(index, order_id) {
				let that = this;
				if (!order_id)
					return that.$util.Tips({
						title: '缺少订单号无法取消订单'
					});
				orderCancel(order_id)
					.then(res => {
						return that.$util.Tips({
								title: res.msg,
								icon: 'success'
							},
							function() {
								that.orderList.splice(index, 1);
								that.$set(that, 'orderList', that.orderList);
								that.$set(that.orderData, 'unpaid_count', that.orderData.unpaid_count - 1);
								that.getOrderData();
							}
						);
					})
					.catch(err => {
						return that.$util.Tips({
							title: err
						});
					});
			},
			
			getContract(oid) {
				userSign(oid).then(res => {
					if (res.status == 200) {
						uni.hideLoading()
						uni.navigateTo({
							url: `/pages/annex/web_view/index?url=${res.data.contract_url}`
						});
					} else {
						uni.hideLoading()
						return that.$util.Tips({
							title: isCRes.msg
						});
					}
				})
			},
			
			goAliPay(order_id, oid, isContract) {
				uni.showLoading({
					title: '加载中...'
				})
				isAttestation().then(res1 => {
					if (res1.status == 200) {
						if (!res1.data.is_attestation) {
							uni.hideLoading()
							uni.navigateTo({
								url: '/pages/lease/real-name'
							})
							return
						} else {
							
							
							if (isContract == 0 || isContract == 1 || isContract == 2) {
								this.getContract(oid)
							} else {
								this.goOrderPay(order_id, oid)
							}
							
							// isContract(oid).then(res => {
							// 	if (res.status == 200) {
							// 		if (res.data.isContract == 0 || res.data.isContract == 1 || res.data.isContract == 2) {
							// 			this.getContract(oid)
							// 		} else {
							// 			this.goOrderPay(order_id, oid)
							// 		}
							// 	} else {
							// 		uni.hideLoading()
							// 		return that.$util.Tips({
							// 			title: res.msg
							// 		})
							// 	}
							// })
						}
					}
				})
			},
			
			goOrderPay(order_id, oid) {
				const that = this
				this.$set(this, 'pay_order_id', order_id);
				
				// if (this.appType == 2) {
				// 	uni.hideLoading()
				// 	this.$set(this, 'pay_close', true)
				// } else {
					orderPay({
						uni: order_id,
						paytype: 'alipay',
						'from': 'alipay',
						quitUr: ''
					}).then(res => {
						uni.hideLoading()
						const prePayTn = res.data.result.jsConfig.prePayTn
						my.tradePay({
							tradeNO: prePayTn ? prePayTn : res.data.result.jsConfig.tradeNo,
							success: (resd) => {
								if (
								  resd.resultCode == "9000" ||
								  resd.resultCode == "8000" ||
								  resd.resultCode == "6004"
								) {
								  
								  that.loadend = false;
								  that.page = 1;
								  that.$set(that, 'orderList', []);
								  that.getOrderList();
								  console.log(resd, "支付完成");
								} else {
								  console.log(resd, "支付失败");
								}
							},
							fail: (resd) => {
								console.log(resd, "支付状态");
							}
						})
					})
				// }
			},
			
			
			/**
			 * 打开支付组件
			 *
			 */
			goPay: function(order_id, oid, isContract) {
				this.goAliPay(order_id, oid, isContract)
			},
			/**
			 * 支付成功回调
			 *
			 */
			pay_complete: function() {
				this.loadend = false;
				this.page = 1;
				this.$set(this, 'orderList', []);
				this.pay_close = false;
				uni.navigateTo({
					url: '/pages/goods/order_pay_status/index?order_id=' + this.pay_order_id +
						'&msg=支付成功&type=3&totalPrice=' + this.totalPrice
				})
				this.pay_order_id = '';
				this.getOrderData();
				this.getOrderList();
			},
			/**
			 * 支付失败回调
			 *
			 */
			pay_fail: function() {
				this.pay_close = false;
				this.pay_order_id = '';
			},
			goBillList(order_id, o_id) {
				if (!order_id)
					return that.$util.Tips({
						title: '缺少订单号无法查看订单详情'
					});
				uni.navigateTo({
					url: '/pages/lease/my-bill-detail?order_id=' + order_id + '&o_id=' + o_id
				})
			},
			/**
			 * 去订单详情
			 */
			goOrderDetails: function(order_id) {
				if (!order_id)
					return that.$util.Tips({
						title: '缺少订单号无法查看订单详情'
					});
					
				uni.navigateTo({
					url: '/pages/lease/order-detail?order_id=' + order_id
				});
					
				// // #ifdef MP
				// uni.showLoading({
				// 	title: '正在加载'
				// });
				// openOrderSubscribe()
				// 	.then(() => {
				// 		uni.hideLoading();
				// 		uni.navigateTo({
				// 			url: '/pages/goods/order_details/index?order_id=' + order_id
				// 		})
				// 	})
				// 	.catch(err => {
				// 		uni.hideLoading();
				// 	});
				// // #endif
				// // #ifndef MP
				// uni.navigateTo({
				// 	url: '/pages/goods/order_details/index?order_id=' + order_id
				// });
				// // #endif
			},
			/**
			 * 切换类型
			 */
			statusClick: function(status) {
				if(this.loading) return
				if (status === this.orderStatus) return;
				this.orderStatus = status;
				this.loadend = false;
				this.page = 1;
				this.$set(this, 'orderList', []);
				this.getOrderList();
			},
			tabClick: function(item) {
				if(this.loading) return
				if (item.id === this.orderStatus) return;
				this.orderStatus = item.id;
				this.tabCurrent = item.index
				this.loadend = false;
				this.page = 1;
				this.$set(this, 'orderList', []);
				this.getOrderList();
			},
			/**
			 * 获取订单列表
			 */
			getOrderList: function() {
				console.log('getOrderList')
				let that = this;
				if (that.loadend) return;
				if (that.loading) return;
				that.loading = true;
				that.loadTitle = '加载更多';
				getOrderList({
						type: that.orderStatus,
						page: that.page,
						limit: that.limit
					})
					.then(res => {
						let list = res.data || [];
						let loadend = list.length < that.limit;
						console.log(loadend)
						that.orderList = that.$util.SplitArray(list, that.orderList);
						that.$set(that, 'orderList', that.orderList);
						that.loadend = loadend;
						that.loading = false;
						that.loadTitle = loadend ? '没有更多内容啦~' : '加载更多';
						that.page = that.page + 1;
					})
					.catch(err => {
						that.loading = false;
						that.loadTitle = '加载更多';
					});
			},

			/**
			 * 删除订单
			 */
			delOrder: function(order_id, index) {
				let that = this;
				uni.showModal({
				    title: '删除订单',
				    content: '确定删除该订单',
					confirmColor: '#1F1F1F',
				    success: function (res) {
				        if (res.confirm) {
							orderDel(order_id)
								.then(res => {
									that.orderList.splice(index, 1);
									that.$set(that, 'orderList', that.orderList);
									that.$set(that.orderData, 'unpaid_count', that.orderData.unpaid_count - 1);
									that.getOrderData();
									return that.$util.Tips({
										title: '删除成功',
										icon: 'success'
									});
								})
								.catch(err => {
									return that.$util.Tips({
										title: err
									});
								});
				        } else if (res.cancel) {
							return that.$util.Tips({
										title: '已取消'
									});
				        }
				    }
				});
				
			}
		},
		onReachBottom: function() {
			this.getOrderList();
		}
	};
</script>

<style scoped lang="scss">
	.my-order .header {
		height: 260rpx;
		padding: 0 30rpx;
	}

	.my-order .header .picTxt {
		height: 190rpx;
	}

	.my-order .header .picTxt .text {
		color: rgba(255, 255, 255, 0.8);
		font-size: 26rpx;
		font-family: 'Guildford Pro';
	}

	.my-order .header .picTxt .text .name {
		font-size: 34rpx;
		font-weight: bold;
		color: #fff;
		margin-bottom: 20rpx;
	}

	// .my-order .header .picTxt .pictrue {
	// 	width: 192rpx;
	// 	height: 192rpx;
	// }

	.my-order .header .picTxt .pictrue image {
		width: 100%;
		height: 100%;
	}

	.my-order .nav {
		background-color: #fff;
		width: 100%;
		height: 140rpx;
		border-radius: 6rpx;
	}

	.my-order .nav .item {
		text-align: center;
		font-size: 26rpx;
		color: #282828;
		padding: 27rpx 0;
		border-bottom: 5rpx solid transparent;
	}

	.my-order .nav .item.on {
		/* #ifdef H5 || MP */
		font-weight: bold;
		/* #endif */
		/* #ifdef APP-PLUS */
		color: #000;
		/* #endif */
		border-color: var(--view-theme);
	}

	.my-order .nav .item .num {
		margin-top: 18rpx;
	}

	.my-order .list {
		width: 690rpx;
		margin: 14rpx auto 0 auto;
	}

	.my-order .list .item {
		background-color: #fff;
		border-radius: 6rpx;
		margin-bottom: 24rpx;
		border-radius: 16rpx;
		overflow: hidden;
		padding: 0 24rpx;
	}

	.my-order .list .item .title {
		height: 84rpx;
		// padding: 0 30rpx;
		border-bottom: 1rpx solid #eee;
		font-size: 28rpx;
		color: #282828;
	}

	.my-order .list .item .title .sign {
		font-size: 24rpx;
		padding: 0 7rpx;
		height: 36rpx;
		margin-right: 15rpx;
	}

	.my-order .list .item .item-info {
		// padding: 0 30rpx;
		margin-top: 22rpx;
		padding-bottom: 22rpx;
		border-bottom: 0.5px solid #eee;
	}

	.my-order .list .item .item-info .pictrue {
		width: 192rpx;
		height: 192rpx;
	}

	.my-order .list .item .item-info .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 6rpx;
	}

	.my-order .list .item .item-info .text {
		width: 414rpx;
		font-size: 28rpx;
		color: #999;
	}

	.my-order .list .item .item-info .text .name {
		width: 100%;
		color: #282828;
		font-size: 32rpx;
		word-break: break-all;
	}
	
	.sku-item {
		margin-top: 24rpx;
		font-size: 24rpx;
		word-break: break-all;
	}
	
	.sku-item2 {
		margin-top: 8rpx;
		font-size: 24rpx;
	}

	.my-order .list .item .item-info .text .money {
		text-align: right;
	}
	
	.my-order .list .item .item-info .text .money .return{
		// color: var(--view-priceColor);
		margin-top: 10rpx;
		font-size: 24rpx;
	}

	.my-order .list .item .totalPrice {
		font-size: 26rpx;
		color: #282828;
		text-align: right;
		margin: 27rpx 0 0 30rpx;
		padding: 0 30rpx 30rpx 0;
		border-bottom: 1rpx solid #eee;
	}

	.my-order .list .item .totalPrice .money {
		font-size: 28rpx;
		font-weight: bold;
		color:  var(--view-priceColor);
	}

	.my-order .list .item .rent {
		font-size: 24rpx;
		color: #1F1F1F;
		text-align: right;
		margin-top: 24rpx;
		
		.money {
			font-weight: bold;
			color: #FF1F2E
		}
		
		.num {
			font-weight: bold;
			font-size: 28rpx;
		}
		// height: 107rpx;
		// padding: 0 30rpx;
	}

	.my-order .list .item .bottom {
		height: 107rpx;
		// padding: 0 30rpx;
	}

	.my-order .list .item .bottom .bnt {
		// width: 176rpx;
		padding: 0 20rpx;
		height: 60rpx;
		text-align: center;
		line-height: 60rpx;
		color: #fff;
		border-radius: 50rpx;
		font-size: 27rpx;
	}

	.my-order .list .item .bottom .bnt.cancelBnt {
		border: 1rpx solid #EBEBEB;
		color: #1F1F1F;
	}

	.my-order .list .item .bottom .bnt~.bnt {
		margin-left: 17rpx;
	}

	.noCart {
		margin-top: 171rpx;
		padding-top: 0.1rpx;
	}

	.noCart .pictrue {
		width: 414rpx;
		height: 336rpx;
		margin: 78rpx auto 56rpx auto;
	}

	.noCart .pictrue image {
		width: 100%;
		height: 100%;
	}

	.line2 {
		word-break: break-all;
	}
	
	
	.head-bar {
		background-color: #fff;
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
	}
	
	.f-color {
		color: #39CCC2;
	}
	
	.b-color {
		background-color: #39CCC2;
	}
	
	.cancle-msg {
		color: #FF271F;
		font-size: 24rpx;
	}
	
	.timeline {
		position: relative;
		padding: 40rpx 0 0 0;
		// max-height: 70vh;
		// overflow: scroll;
		
		.popup-close {
			position: absolute;
			right: 30rpx;
			top: 60rpx;
			z-index: 2;
			transform: translateY(-50%);
			font-size: 35rpx;
			color: #8a8a8a;
			font-weight: normal;
		}
		
		.timeline-name {
			font-size: 28rpx;
			font-weight: bold;
			color: #333333;
			text-align: center;
		}
		
		.timeline-nav {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 24rpx;
			margin-top: 24rpx;
			width: 100%;
			height: 80rpx;
			background: #F5F5F5;
			font-size: 28rpx;
			font-weight: 400;
			color: #333333;
			
			image {
				width: 44rpx;
				height: 44rpx;
				border-radius: 8rpx;
			}
		}
		
		.list {
			margin-top: 38rpx;
			position: relative;
			padding-left: 44rpx;
			height: 800rpx;
			
			.item {
				position: relative;
				z-index: 14;
				display: flex;
				margin-top: 48rpx;
				
				&:first-child { 
					margin-top: 0; 
					
					.title,.time {
						color: #39CCC2;
					}
					
					.circle {
						background: #39CCC2;
					}
				}
				
				.circle {
					position: relative;
					z-index: 10;
					margin-right: 30px;
					margin-top: 12rpx;
					width: 18rpx;
					height: 18rpx;
					background: #B8B8B8;
					border-radius: 50%;
				}
				
				.title {
					flex: 1;
					margin-right: 30px;
					font-size: 28rpx;
					color: #666666;
					line-height: 40rpx;
				}
				
				.time {
					margin-top: 16rpx;
					font-size: 24rpx;
					color: #B8B8B8;
				}
			}
			
			.line {
				position: absolute;
				top: 16rpx;
				left: 52rpx;
				z-index: 10;
				width: 2rpx;
				height: calc(100% - 80rpx);
				background-color: #F5F5F5;
			}
		}
		
		.pop-btn {
			margin: 60rpx auto 0 auto;
			width: 430rpx;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			background: #39CCC2;
			border-radius: 40rpx;
			font-size: 28rpx;
			font-weight: 500;
			color: #FFFFFF;
		}
	}
	
	.icon-mer {
		width: 28rpx;
		height: 28rpx;
		margin-right: 8rpx;
	}
</style>
